<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue v-show v-if 的区别</title>
    <style>
        div {
            padding: 10px;
            border: 1px solid green;
        }

        h2 {
            padding: 10px;
            border: 1px solid rgb(228, 95, 210);
        }
    </style>
</head>

<body>
    <div id="app">
        <h2>text here：<br>
            <!-- v-if 条件为false时，DOM中不会产生相关元素，当只切换一次时使用-->
            <!-- v-show 条件为false时，只是将该元素的display设为none，当需要频繁切换时使用-->
            <span v-if="isShow" id="ifSpn">v-if: {{message}}</span><br>
            <span v-show="isShow" id="showSpn">v-show: {{message}}</span>
        </h2>
        <button v-show="isShow" @click="isShow=!isShow">隐藏</button>
        <button v-show="!isShow" @click="isShow=!isShow">显示</button>
    </div>

    <script src="js/vue.js"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data: {
                message: 'this is a vue demo!',
                isShow:true
            },
            computed: {

            },
            methods: {
                action: function () {
                    this.message = 'hello!'
                }
            }
        });
    </script>
</body>

</html>
